IndexOf Method

Summary

Returns the index of the specified item if it is found in the collection.

Syntax
C#
VB
C++
public virtual int IndexOf( 
   T item 
) 
Public Overridable Function IndexOf( 
   ByVal item As T 
) As Integer 
public:  
   virtual Int32 IndexOf( 
      T item 
   ) 

Parameters

item Object to test.

Return Value

The index of the specified item if it is found in the collection.

Remarks

if the object is not found in the collection, the return value is -1.

Example
C#
VB
using Leadtools; 
using Leadtools.Dicom; 
using Leadtools.Medical3D; 
using Leadtools.Codecs; 
using Leadtools.MedicalViewer; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Annotations.Engine; 
using Leadtools.Annotations.Designers; 
 
 
// Sample to test the MedicalViewerCollection class. 
 
public void MedicalViewerCollectionExample() 
{ 
   MedicalViewerCollection<string> rc = new MedicalViewerCollection<string>(); 
   rc.ItemAdded += new EventHandler<MedicalViewerCollectionEventArgs<string>>(MedicalViewerCollection_ItemAdded); 
   rc.ItemRemoved += new EventHandler<MedicalViewerCollectionEventArgs<string>>(MedicalViewerCollection_ItemRemoved); 
 
   // add a few items  
   string item1 = "item 1"; 
   string item2 = "item 2"; 
   string item3 = "item 3"; 
 
   rc.Add(item1); 
   rc.Add(item2); 
   rc.Add(item3); 
 
   // insert an item  
   string newItem2 = "new item 2"; 
   rc.Insert(1, newItem2); 
 
   // check if collection contains this new item  
   Assert.IsTrue(rc.Contains(newItem2)); 
 
   // remove this new item  
   rc.Remove(newItem2); 
   Assert.IsTrue(!rc.Contains(newItem2)); 
 
   // remove the last item  
   rc.RemoveAt(rc.Count - 1); 
   Assert.IsTrue(rc.Count == 2); 
 
   // send the first item to the end of the collection  
   rc.SendToBack(item1, true); 
   Assert.IsTrue(rc.IndexOf(item1) == rc.Count - 1); 
 
   // bring it back to the front  
   rc.BringToFront(item1, true); 
   Assert.IsTrue(rc.IndexOf(item1) == 0); 
 
   // copy to an array  
   string[] items = new string[rc.Count]; 
   rc.CopyTo(items, 0); 
   Assert.IsTrue(items.Length == rc.Count); 
   for (int i = 0; i < items.Length; i++) 
      Assert.IsTrue(items[i] == rc[i]); 
 
   // loop throw the items and show them  
   foreach (string str in rc) 
      Console.WriteLine(str); 
 
   // clean the collection  
   rc.Clear(); 
   Assert.IsTrue(rc.Count == 0); 
} 
 
private void MedicalViewerCollection_ItemAdded(System.Object sender, MedicalViewerCollectionEventArgs<string> e) 
{ 
   Console.WriteLine("The Item ((" + e.Item.ToString() + ")) Has been added to the collection"); 
} 
 
private void MedicalViewerCollection_ItemRemoved(System.Object sender, MedicalViewerCollectionEventArgs<string> e) 
{ 
   Console.WriteLine("The Item ((" + e.Item.ToString() + ")) Has been removed from the collection"); 
}  
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.MedicalViewer 
 
'Sample to test the MedicalViewerCollection class. 
Public Sub MedicalViewerCollectionExample() 
   Dim rc As MedicalViewerCollection(Of String) = New MedicalViewerCollection(Of String)() 
   AddHandler rc.ItemAdded, AddressOf MedicalViewerCollection_ItemAdded 
   AddHandler rc.ItemRemoved, AddressOf MedicalViewerCollection_ItemRemoved 
 
   ' add a few items  
   Dim item1 As String = "item 1" 
   Dim item2 As String = "item 2" 
   Dim item3 As String = "item 3" 
 
   rc.Add(item1) 
   rc.Add(item2) 
   rc.Add(item3) 
 
   ' insert an item  
   Dim newItem2 As String = "new item 2" 
   rc.Insert(1, newItem2) 
 
   ' check if collection contains this new item  
   Debug.Assert(rc.Contains(newItem2)) 
 
   ' remove this new item  
   rc.Remove(newItem2) 
   Debug.Assert((Not rc.Contains(newItem2))) 
 
   ' remove the last item  
   rc.RemoveAt(rc.Count - 1) 
   Debug.Assert(rc.Count = 2) 
 
   ' send the first item to the end of the collection  
   rc.SendToBack(item1, True) 
   Debug.Assert(rc.IndexOf(item1) = rc.Count - 1) 
 
   ' bring it back to the front  
   rc.BringToFront(item1, True) 
   Debug.Assert(rc.IndexOf(item1) = 0) 
 
   ' copy to an array  
   Dim items As String() = New String(rc.Count - 1) {} 
   rc.CopyTo(items, 0) 
   Debug.Assert(items.Length = rc.Count) 
   Dim i As Integer = 0 
   Do While i < items.Length 
      Debug.Assert(items(i) = rc(i)) 
      i += 1 
   Loop 
 
   ' loop throw the items and show them  
   For Each str As String In rc 
      Console.WriteLine(str) 
   Next str 
 
   ' clean the collection  
   rc.Clear() 
   Debug.Assert(rc.Count = 0) 
End Sub 
 
Private Sub MedicalViewerCollection_ItemAdded(ByVal sender As System.Object, ByVal e As MedicalViewerCollectionEventArgs(Of String)) 
   Console.WriteLine("The Item ((" & e.Item.ToString() & ")) Has been added to the collection") 
End Sub 
 
Private Sub MedicalViewerCollection_ItemRemoved(ByVal sender As System.Object, ByVal e As MedicalViewerCollectionEventArgs(Of String)) 
   Console.WriteLine("The Item ((" & e.Item.ToString() & ")) Has been removed from the collection") 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.MedicalViewer Assembly